<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>个人资料 - AI简历分析</title>
    <style>
        /* 整体样式 */
        .profile-management-container {
            background-color: #f5f5f5;
            min-height: 100vh;
            padding: 20px;
            font-family: Arial, sans-serif;
        }

        /* 顶部控制栏 */
        .top-control-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding: 0 20px;
        }

        .page-title {
            font-size: 24px;
            font-weight: bold;
            color: #333;
        }

        .settings-icon {
            width: 24px;
            height: 24px;
            cursor: pointer;
            background-color: #666;
            border-radius: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
        }

        /* 用户信息卡片 */
        .user-info-card {
            background: white;
            border-radius: 12px;
            padding: 24px;
            margin: 0 auto 30px;
            max-width: 400px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .avatar-section {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .circular-avatar {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background-color: #007bff;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            font-weight: bold;
            margin-right: 16px;
        }

        .avatar-image {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            object-fit: cover;
        }

        .user-details {
            flex: 1;
        }

        .username {
            font-size: 18px;
            font-weight: bold;
            color: #333;
            margin-bottom: 4px;
        }

        .email {
            font-size: 14px;
            color: #666;
            margin-bottom: 8px;
        }

        .sync-status {
            font-size: 12px;
            color: #28a745;
            font-weight: 500;
        }

        /* 头像选择弹窗样式 */
        .avatar-modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
        }

        .modal-content {
            background-color: white;
            margin: 10% auto;
            padding: 20px;
            border-radius: 8px;
            width: 80%;
            max-width: 500px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }

        .avatar-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 15px;
            margin-top: 15px;
        }

        .avatar-option {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            cursor: pointer;
            border: 3px solid transparent;
            transition: border-color 0.3s;
        }

        .avatar-option:hover {
            border-color: #007bff;
        }

        .avatar-option.selected {
            border-color: #28a745;
        }

        .modal-actions {
            display: flex;
            justify-content: flex-end;
            margin-top: 20px;
            gap: 10px;
        }

        .modal-btn {
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
        }

        .confirm-btn {
            background-color: #007bff;
            color: white;
            border: none;
        }

        .cancel-btn {
            background-color: #f8f9fa;
            border: 1px solid #ddd;
        }

        .change-avatar-button {
            margin-top: 10px;
            padding: 8px 16px;
            background: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        .back-button {
            color: #1d2223;
            text-decoration: none;
            margin-right: 15px;
            font-size: 16px;
        }

        .back-button:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
<div class="profile-management-container">
    <!-- 顶部控制栏 -->
    <div class="top-control-bar">
        <div>
            <a th:href="@{/interview}" class="back-button">← 返回主页</a>
            <span class="page-title">个人资料</span>
        </div>
    </div>

    <!-- 用户信息卡片 -->
    <div class="user-info-card">
        <div class="avatar-section">
            <div class="circular-avatar">


                <th:block th:unless="${currentUser.avatarUrl != null and currentUser.avatarUrl != ''}">

                </th:block>
            </div>
            <div class="user-details">
                <div class="username" th:text="${currentUser.username != null} ? ${currentUser.username} : '个人'">个人</div>
                <div class="email" th:text="${currentUser.email}"></div>
                <div class="sync-status">同步已启用</div>
            </div>
        </div>

        <button class="change-avatar-button" onclick="openAvatarModal()">更改头像</button>

        <!-- 显示操作结果消息 -->
        <div th:if="${success}" style="color: green; margin-top: 10px;" th:text="${success}"></div>
        <div th:if="${error}" style="color: red; margin-top: 10px;" th:text="${error}"></div>
    </div>

    <div id="avatarModal" class="avatar-modal">
        <div class="modal-content">
            <h3>选择头像</h3>
            <div class="avatar-grid">
                <!-- 预定义的头像选项 -->
                <div th:each="avatar : ${avatarOptions}">
                    <input type="radio" name="avatarOption" th:id="${'avatar' + avatarStat.index}" th:value="${avatar}">
                    <label th:for="${'avatar' + avatarStat.index}">

                    </label>
                </div>
            </div>
            <div class="modal-actions">
                <button class="modal-btn cancel-btn" onclick="closeAvatarModal()">取消</button>
                <button class="modal-btn confirm-btn" onclick="confirmAvatarSelection()">确认</button>
            </div>
        </div>
    </div>
</div>

<script>
    // 打开头像选择弹窗
    function openAvatarModal() {
        document.getElementById('avatarModal').style.display = 'block';
    }

    // 关闭头像选择弹窗
    function closeAvatarModal() {
        document.getElementById('avatarModal').style.display = 'none';
    }

    // 确认头像选择
    function confirmAvatarSelection() {
        const selectedAvatar = document.querySelector('input[name="avatarOption"]:checked');
        if (selectedAvatar) {
            // 提交表单
            const form = document.createElement('form');
            form.method = 'post';
            form.action = '/profile/select-avatar';

            const input = document.createElement('input');
            input.type = 'hidden';
            input.name = 'avatarUrl';
            input.value = selectedAvatar.value;

            form.appendChild(input);
            document.body.appendChild(form);
            form.submit();
        } else {
            alert('请选择一个头像');
        }
    }

    // 头像选项点击事件
    document.addEventListener('DOMContentLoaded', function() {
        const avatarOptions = document.querySelectorAll('.avatar-option');
        avatarOptions.forEach(option => {
            option.addEventListener('click', function() {
                const radio = this.previousElementSibling;
                radio.checked = true;

                // 移除其他选中样式
                avatarOptions.forEach(opt => opt.classList.remove('selected'));
                // 添加当前选中样式
                this.classList.add('selected');
            });
        });
    });
</script>
</body>
</html>